package com.pvdnc.systemdebugger.compacter;

import android.os.IBinder;
import android.os.Parcel;
import android.os.RemoteException;

public class PBServiceManagerProxy implements IPBServiceManager {
    private IBinder mRemote;
    public PBServiceManagerProxy(IBinder remote){
        this.mRemote=remote;
    }

    @Override
    public void addService(String name, IBinder local) {
        Parcel data=Parcel.obtain();
        data.writeString(name);
        data.writeStrongBinder(local);
        Parcel reply=Parcel.obtain();
        try {
            mRemote.transact(IPBServiceManager.CODE_ADD_SERVICE,data,reply,0);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    @Override
    public IBinder getService(String name) {
        Parcel data=Parcel.obtain();
        data.writeString(name);
        Parcel reply=Parcel.obtain();
        try {
            mRemote.transact(IPBServiceManager.CODE_GET_SERVICE,data,reply,0);
            return reply.readStrongBinder();
        } catch (RemoteException e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public IBinder asBinder() {
        return mRemote;
    }
}
